package indi.woniu.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import indi.woniu.entity.*;
import indi.woniu.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
@CrossOrigin
@RestController
@RequestMapping("/question")
public class QuestionController {
    @Autowired
    private QuestionService questionService;
    @RequestMapping("/findAll")
    public ResponseEntity findAll(@RequestBody FormInline formInline){
        PageHelper.startPage(formInline.getPage(),formInline.getLimit());

        List<Question> questions = questionService.findAll(formInline);
        PageInfo<Question> listPageInfo = new PageInfo<Question>(questions);
        return new ResponseEntity(200,"成功",listPageInfo);
    }
    @RequestMapping("/findByCondition")
    public  ResponseEntity findByCondition(@RequestBody Condition condition){
        PageHelper.startPage(condition.getFormInline().getPage(),condition.getFormInline().getLimit());
        List<Map<String,Object>> questions =  questionService.findByCondition(condition);
        PageInfo listPageInfo = new PageInfo(questions);
        return new ResponseEntity(200,"成功",listPageInfo);
    }
    @RequestMapping("/findQuestionType")
    public ResponseEntity findQuestionType(){
        List questionType = questionService.findQuestionType();
        return new ResponseEntity(200,"成功",questionType);
    }
    @RequestMapping("/findQuestionLevel")
    public ResponseEntity findQuestionLevel(){

        List questionLevel = questionService.findQuestionLevel();
        return new ResponseEntity(200,"成功",questionLevel);
    }



}
